
Imports std
Imports System.IO

Module line

    Function Main(ByVal args() As String) As Int32
        On Error Resume Next
        Dim reader As TextReader = Nothing
        Dim count As Int32
        Dim i As Int32
        Dim input As String

        If args.Length() = 0 Then
            raiseError("argument count error, input0 input1 ... inputN, if inputX is '/-', use console", _
                            errorHandle.errorType.critical)
            count = -1
        Else
            count = 0
            For i = 0 To args.Length() - 1
                If args(i) = "/-" Then
                    reader = Console.In
                Else
                    reader = New StreamReader(New FileStream(args(i), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                End If
                assert(Not reader Is Nothing, "file no found, " + args(i))

                input = reader.ReadLine
                While Not input Is Nothing
                    count += 1
                    input = reader.ReadLine
                End While
                closestream(reader)
            Next
            Console.WriteLine(count)
        End If

        Return count
    End Function

End Module
